<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
	<style>
        .countdown {
            font-size: 24px;
            text-align: center;
            font-family: Arial, sans-serif;
            padding: 20px;
            background-color: #f0f0f0;
            border-radius: 10px;
        }
        .countdown span {
            margin: 0 10px;
            padding: 5px 10px;
            background-color: #333;
            color: white;
            border-radius: 5px;
        }
    </style>
</head>
<body>
	<div class="countdown">
        距离五一还有：
        <span id="days">0</span>天
        <span id="hours">0</span>时
        <span id="minutes">0</span>分
        <span id="seconds">0</span>秒
    </div>
 	<script type="text/javascript">
 		let span = document.querySelectorAll("span")

 		function time(){
 			let now = new Date().getTime()
 			let endTime = new Date("2025/5/1, 00:00:00")
 			// 获取5.1到现在的时间差
 			let diff = endTime - now
 			console.log(diff)

 			let day = parseInt(diff/1000/60/60/24)
 			let hour = parseInt(diff/1000/60/60%24)
 			let minute = parseInt(diff/1000/60%60)
 			let second = parseInt(diff/1000%60)

 			console.log(day,hour,minute,second)

 			hour = hour < 10 ? '0' + hour : hour
 			minute = minute < 10 ? "0" + minute : minute
 			second = second <10 ? "0" + second : second

 			span[0].innerText = day
 			span[1].innerText = hour
 			span[2].innerText = minute
 			span[3].innerText = second

 		}
 		time()
 		setInterval(time,1000)
 	</script>
</body>
</html>